const {
    arrayToMap
} = rx
const app = new Vue({
    el: '#app',
    data: {
        transactionLog: {},
        columns: {
            tlogActiveVoColumns: [
                new TableColumn({prop: 'loginName', title: '用户名'}),
                new TableColumn({prop: 'sysUserRoleList', title: '用户类型', customComponent: true}),
                new TableColumn({prop: 'loginSource', title: '来源IP'}),
                new TableColumn({prop: 'createTime', title: '创建时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'lastLoginTime', title: '上次登录时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({
                    prop: 'status', title: '状态',
                    formatter: fieldFormatter.facade(fieldFormatter.tlogSecurity.statusMap),
                }),
            ],
            tlogOperationColumns: [
                new TableColumn({prop: 'operObject', title: '对象'}),
                new TableColumn({
                    prop: 'operType', title: '类型',
                    formatter: fieldFormatter.facade(fieldFormatter.tlogSecurity.operTypeMap),
                }),
                new TableColumn({prop: 'loginName', title: '用户名'}),
                new TableColumn({prop: 'sysUserRoleList', title: '用户类型', customComponent: true}),
                new TableColumn({prop: 'sourceIp', title: '来源IP'}),
                new TableColumn({prop: 'operTime', title: '时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'message', title: '消息'}),
                new TableColumn({prop: 'operating', title: '查看', customComponent: true}),
            ],
            tlogSecurityVoColumns: [
                new TableColumn({
                    prop: 'eventType', title: '事件类型',
                    formatter: fieldFormatter.facade(fieldFormatter.tlogSecurity.eventTypeMap),
                }),
                new TableColumn({prop: 'eventResult', title: '事件结果'}),
                new TableColumn({prop: 'loginName', title: '用户名'}),
                new TableColumn({prop: 'sysUserRoleList', title: '用户类型', customComponent: true}),
                new TableColumn({prop: 'sourceIp', title: '来源IP'}),
                new TableColumn({prop: 'actTime', title: '时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'message', title: '消息'}),
                new TableColumn({prop: 'operating', title: '查看', customComponent: true}),
            ],
            tlogSystemVoColumns: [
                new TableColumn({prop: 'level', title: '级别', customComponent: true}),
                new TableColumn({prop: 'actTime', title: '发生时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'location', title: '发生位置'}),
                new TableColumn({prop: 'processId', title: '进程号'}),
                new TableColumn({prop: 'sourceIp', title: '来源IP'}),
                new TableColumn({prop: 'message', title: '消息'}),
                new TableColumn({prop: 'operating', title: '查看', customComponent: true}),

            ],
        },
        /**
         * 级别类型列表， 1：信息，2：警告，3：错误
         */
        levelList:{'1':'信息','2':'警告','3':'错误'},

        /**
         * 小图标
         * '1':'信息','2':'警告','3':'错误'
         */
        logIconImgList:{'1':'logicon_info.gif','2':'logicon_warning.gif','3':'logicon_err.gif'},
        sysRoleList: [],
        sysRoleMap: new Map(),

    },
    methods: {
        async initData() {
            this.sysRoleListInit()
            this.transactionLog = await transactionLogApi.getPageData();
        },
        async tlogOperationViewInfo(row){
            var endIndex=this.totalTlogOperation-1;
            var entity =new TlogOperationVo();
            var page = new Page();
            page.current=1;
            page.size=10;
            page = await tlogOperationApi.page(page, entity);
            forward('/security-log/see/admin_security_auditlogdetail',{
                id: row.id,
                page:page,
                entity:entity,
                pagestartIndex:0,
                endIndex:endIndex,
            });

        },

        async tlogSecurityViewInfo(row){
            var endIndex=this.totalTlogSecurity-1;
            var entity =new TlogSecurityVo();
            var page = new Page();
            page.current=1;
            page.size=10;
            page = await tlogSecurityApi.page(page, entity);
            forward('/security-log/see/admin_security_securitylogdetail',{
                id: row.id,
                page:page,
                entity:entity,
                pagestartIndex:0,
                endIndex:endIndex,
            });

        },
        async tlogSystemViewInfo(row){
            var endIndex=this.totalTlogSystem-1;
            var entity =new TlogSystemVo();
            var page = new Page();
            page.current=1;
            page.size=10;
            page = await tlogSystemApi.page(page, entity);
            forward('/security-log/see/admin_security_syslogdetail',{
                id: row.id,
                page:page,
                entity:entity,
                pagestartIndex:0,
                endIndex:endIndex,
            });

        },
        imgUrl: function (val) {
            return "/static/img/"+this.logIconImgList[val];
        },
        async sysRoleListInit() {
            this.sysRoleList = await sysRoleApi.listForAll()
            this.sysRoleMap = arrayToMap(this.sysRoleList, ({id}) => id, ({name}) => name)
        },
    },
    computed: {
        fieldFormatter() {
            return fieldFormatter
        },
    },
    async mounted() {
        await this.initData();
    },

});





